package com.wfx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wfx.entity.*;
import com.wfx.service.IWxbCustomerService;
import com.wfx.service.IWxbGoodsBrandService;
import com.wfx.service.IWxbGoodsCatService;
import com.wfx.service.IWxbGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhu
 * @since 2021-01-21
 */
@RestController
@CrossOrigin
@RequestMapping("/goods")
@Api(description = "自媒体查看商品")
public class WxbGoodsController {

    @Autowired
    private IWxbGoodsService iWxbGoodsService;

    @Autowired
    private IWxbCustomerService iWxbCustomerService;

    @Autowired
    private IWxbGoodsCatService iWxbGoodsCatService;

    @Autowired
    private IWxbGoodsBrandService iWxbGoodsBrandService;

    @PostMapping("/search")
    @ApiOperation("分页+条件")
    public PageResult<WxbGoods> search(@RequestBody @ApiParam("分页条件") PageDTO<WxbGoods> pageDTO){
        if (pageDTO == null) {
            pageDTO.setPage(1);
            pageDTO.setLimit(5);
        }
        return iWxbGoodsService.searchMedia(pageDTO);
    }
    //商品详情
    @GetMapping("/selectOne")
    public WxbGoods selectOne(String id){
        return iWxbGoodsService.selectByIdOne(id);
    }
    //查询商家
    @PostMapping("/cus")
    public List<WxbCustomer> findCus(){
        return iWxbCustomerService.findAll();
    }
    //查询类目
    @PostMapping("/cat")
    public List<WxbGoodsCat> findCat(String parentId){
        QueryWrapper<WxbGoodsCat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id",parentId);
        return iWxbGoodsCatService.list(queryWrapper);
    }
    //查询品牌
    @PostMapping("/brand")
    public List<WxbGoodsBrand> finBrand(){
        return iWxbGoodsBrandService.list();
    }

}
